package com.tjsinfo.tjsoa.vote.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.Dao.IHQLDao;

public class UnEstimatedStatusAction extends Action {
	private IHQLDao hqlDao;
	public void setHqlDao(IHQLDao hqlDao) {
		this.hqlDao = hqlDao;
	}


	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			String headId = request.getParameter("headId");
			
			String sql="SELECT vote,voteName,COUNT(*) AS unReadNumber FROM TVoteEstimatedStatus WHERE (headId = '"+headId+"') AND (status = '0') GROUP BY vote,voteName";
			List estimatedStatusLists = hqlDao.executeList(sql);
			if("0".equals(request.getParameter("readId"))){
				String read="0";
				if(estimatedStatusLists.size()!=0)read="1";
				response.setContentType("text/html; charset=UTF-8"); 
				response.getWriter().print(read);
				return null;
			}
			
			request.setAttribute("estimatedStatusLists", estimatedStatusLists);
			
			return mapping.findForward("success");
 		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
